package com.egao.orderB.controller;

import com.egao.common.core.web.*;
import com.egao.common.core.annotation.OperLog;
import com.egao.orderB.entity.Bill;
import com.egao.orderB.service.BillService;
import net.sf.json.JSONObject;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.ui.Model;
import net.sf.json.JSONArray;


/**
 *
 * 订单管理
 * @author : Doman
 * @date : 2020-05-28 14:12:19
 * @version ：1.0
 */

@Controller
@RequestMapping("/orderB/bill")
public class BillController extends BaseController {

	@Autowired
	private BillService billService;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("orderB:bill:view")
	@RequestMapping()
	public String view() {
		return "orderB/bill.html";
	}

	/**
	 * 分页查询列表
	 */
	@RequiresPermissions("orderB:bill:list")
	@OperLog(value = "订单管理", desc = "分页查询")
	@ResponseBody
	@RequestMapping("/page")
    public JSONObject list(PageResult2<T> page, Bill bill) throws Exception{
        return billService.list(page, bill, getLoginUser());
    }

    /**
     * 查询全部订单管理
     */
    @RequiresPermissions("orderB:bill:list")
    @OperLog(value = "订单管理", desc = "查询全部")
    @ResponseBody
    @RequestMapping("/list")
    public String list(Bill bill){
        return JSONArray.fromObject(billService.list(bill, getLoginUser())).toString();
    }

    /**
     * 根据id查询订单管理
     */
    @RequiresPermissions("orderB:bill:list")
    @OperLog(value = "订单管理", desc = "根据id查询")
    @ResponseBody
    @RequestMapping("/get")
    public JsonResult get(Bill bill) {
        return JsonResult.ok().setData(billService.getById(bill));
		// 使用关联查询
        //PageParam<bill> pageParam = new PageParam<>();
		//pageParam.put("id", id);
        //List<bill> records = billService.listAll(pageParam.getNoPageParam());
        //return JsonResult.ok().setData(pageParam.getOne(records));
    }


    /**
     * 添加订单管理
     */
    @RequiresPermissions("orderB:bill:save")
    @OperLog(value = "订单管理", desc = "添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/save")
    public JsonResult save(Model model, Bill bill) {
        return billService.save(bill, getLoginUser());
    }

    /**
     * 修改订单管理
     */
    @RequiresPermissions("orderB:bill:update")
    @OperLog(value = "订单管理", desc = "修改", param = false, result = true)
    @ResponseBody
    @RequestMapping("/update")
    public JsonResult update(Model model, Bill bill) {
        return billService.update(bill, getLoginUser());
    }

    /**
     * 删除订单管理
     */
    @RequiresPermissions("orderB:bill:remove")
    @OperLog(value = "订单管理", desc = "删除", result = true)
    @ResponseBody
    @RequestMapping("/remove")
    public JsonResult remove(Bill bill ) {
        return billService.remove(bill, getLoginUser());
    }

    /**
     * 批量添加订单管理
     */
    /**@RequiresPermissions("orderB:bill:save")
    @OperLog(value = "订单管理", desc = "批量添加", param = false, result = true)
    @ResponseBody
    @RequestMapping("/saveBatch")
    public JsonResult saveBatch(@RequestBody List<Bill> list) {
        if (billService.saveBatch(list)) {
            return JsonResult.ok("添加成功");
        }
        return JsonResult.error("添加失败");
    }*/

    /**
     * 批量修改订单管理
     */
    /**@RequiresPermissions("orderB:bill:update")
    @OperLog(value = "订单管理", desc = "批量修改", result = true)
    @ResponseBody
    @RequestMapping("/updateBatch")
    public JsonResult updateBatch(@RequestBody BatchParam<Bill> batchParam) {
        if (batchParam.update(billService, "")) {
            return JsonResult.ok("修改成功");
        }
        return JsonResult.error("修改失败");
    }*/

    /**
     * 批量删除订单管理
     */
    /**@RequiresPermissions("orderB:bill:remove")
    @OperLog(value = "订单管理", desc = "批量删除", result = true)
    @ResponseBody
    @RequestMapping("/removeBatch")
    public JsonResult removeBatch(@RequestBody List<Integer> ids) {
        if (billService.removeByIds(ids)) {
            return JsonResult.ok("删除成功");
        }
        return JsonResult.error("删除失败");
    }*/

}
